package com.amazon.ags.api;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import com.amazon.ags.api.achievements.AchievementsClient;
import com.amazon.ags.api.leaderboards.LeaderboardsClient;
import com.amazon.ags.api.overlay.PopUpLocation;
import com.amazon.ags.api.profiles.ProfilesClient;
import com.amazon.ags.api.whispersync.WhisperSyncClient;
import com.amazon.ags.client.AmazonGamesService;
import com.amazon.ags.client.AmazonGamesStatusHandler;
import com.amazon.ags.client.ServiceProxy;
import com.amazon.ags.client.achievements.AchievementsClientImpl;
import com.amazon.ags.client.achievements.AchievementsService;
import com.amazon.ags.client.achievements.AchievementsServiceProxy;
import com.amazon.ags.client.leaderboards.LeaderboardsClientImpl;
import com.amazon.ags.client.leaderboards.LeaderboardsService;
import com.amazon.ags.client.leaderboards.LeaderboardsServiceProxy;
import com.amazon.ags.client.profiles.ProfilesClientImpl;
import com.amazon.ags.client.profiles.ProfilesService;
import com.amazon.ags.client.profiles.ProfilesServiceProxy;
import com.amazon.ags.client.whispersync.WhisperSyncServiceProxy;
import com.amazon.ags.jni.AGSJniHandler;
import com.amazon.ags.overlay.PopUpManager;
import com.amazon.ags.overlay.PopUpPrefs;
import dalvik.system.PathClassLoader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.EnumSet;

public class AmazonGamesClient
  implements AmazonGames
{
  private static final String APK_PACKAGE_NAME = "com.amazon.ags.app";
  private static final String FEATURE_NAME = "GC";
  private static AmazonGames INSTANCE = null;
  private static final String SOFTKEY_BAR_WRAPPER_CLASS_NAME = "com.amazon.ags.app.util.SoftkeyBarWrapper";
  private static final String SOFTKEY_BAR_WRAPPER_SETUP_METHOD_NAME = "setup";
  private static final String TAG = "GC_" + AmazonGamesClient.class.getSimpleName();
  private AchievementsService achievementsService;
  private AmazonGamesService amazonGamesService;
  public final Handler apiHandler;
  private final Application application;
  private final Context context;
  private LeaderboardsService leaderboardsService;
  private ProfilesService profilesService;

  private AmazonGamesClient(Application paramApplication, AmazonGamesCallback paramAmazonGamesCallback, EnumSet<AmazonGamesFeature> paramEnumSet)
  {
    this.application = paramApplication;
    this.context = this.application.getApplicationContext();
    this.amazonGamesService = new ServiceProxy(new AmazonGamesStatusHandler(paramAmazonGamesCallback), paramEnumSet);
    this.amazonGamesService.bind(this.context);
    this.apiHandler = new Handler();
    this.leaderboardsService = new LeaderboardsServiceProxy(this, this.amazonGamesService, this.apiHandler);
    this.achievementsService = new AchievementsServiceProxy(this, this.amazonGamesService, this.apiHandler);
    this.profilesService = new ProfilesServiceProxy(this, this.amazonGamesService, this.apiHandler);
    PopUpManager.initialize(this.context, this.leaderboardsService, this.achievementsService, this.amazonGamesService);
    enableSoftKeyButton();
  }

  public AmazonGamesClient(Application paramApplication, AmazonGamesService paramAmazonGamesService)
  {
    this.application = paramApplication;
    this.context = this.application.getApplicationContext();
    this.amazonGamesService = paramAmazonGamesService;
    this.amazonGamesService.bind(this.context);
    this.apiHandler = new Handler();
    this.leaderboardsService = new LeaderboardsServiceProxy(this, this.amazonGamesService, this.apiHandler);
    this.achievementsService = new AchievementsServiceProxy(this, this.amazonGamesService, this.apiHandler);
    this.profilesService = new ProfilesServiceProxy(this, this.amazonGamesService, this.apiHandler);
    PopUpManager.initialize(this.context, this.leaderboardsService, this.achievementsService, this.amazonGamesService);
    enableSoftKeyButton();
  }

  public AmazonGamesClient(Application paramApplication, AmazonGamesService paramAmazonGamesService, LeaderboardsService paramLeaderboardsService, AchievementsService paramAchievementsService)
  {
    this.application = paramApplication;
    this.context = this.application.getApplicationContext();
    this.amazonGamesService = paramAmazonGamesService;
    this.amazonGamesService.bind(this.context);
    this.apiHandler = new Handler();
    this.leaderboardsService = paramLeaderboardsService;
    this.achievementsService = paramAchievementsService;
    this.profilesService = new ProfilesServiceProxy(this, this.amazonGamesService, this.apiHandler);
    PopUpManager.initialize(this.context, paramLeaderboardsService, paramAchievementsService, this.amazonGamesService);
    enableSoftKeyButton();
  }

  private void enableSoftKeyButton()
  {
    try
    {
      Class localClass = Class.forName("com.amazon.ags.app.util.SoftkeyBarWrapper", true, new PathClassLoader(this.application.getPackageManager().getApplicationInfo("com.amazon.ags.app", 0).sourceDir, ClassLoader.getSystemClassLoader()));
      Method localMethod = localClass.getDeclaredMethod("setup", new Class[] { Application.class, BroadcastReceiver.class });
      Object localObject = localClass.newInstance();
      Object[] arrayOfObject = new Object[2];
      arrayOfObject[0] = this.application;
      arrayOfObject[1] = new BroadcastReceiver()
      {
        public final void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
        {
          Log.d(AmazonGamesClient.TAG, "GameCircle softkey button pressed.");
          AmazonGamesClient.this.handleSoftkeyButtonPress();
        }
      };
      localMethod.invoke(localObject, arrayOfObject);
      return;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localNameNotFoundException.toString());
      return;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localClassNotFoundException.toString());
      return;
    }
    catch (InstantiationException localInstantiationException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localInstantiationException.toString());
      return;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localIllegalAccessException.toString());
      return;
    }
    catch (SecurityException localSecurityException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localSecurityException.toString());
      return;
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localNoSuchMethodException.toString());
      return;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localIllegalArgumentException.toString());
      return;
    }
    catch (InvocationTargetException localInvocationTargetException)
    {
      Log.e(TAG, "Failed to enable softkey button: " + localInvocationTargetException.toString());
    }
  }

  public static AmazonGames getInstance()
  {
    if (INSTANCE == null)
      Log.e(TAG, "AmazonGames is not initialized.  Be sure to call AmazonGamesClient.initialize() first");
    return INSTANCE;
  }

  private void handleSoftkeyButtonPress()
  {
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          Message localMessage = Message.obtain();
          localMessage.what = 30;
          localMessage.setData(new Bundle());
          AmazonGamesClient.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          Log.e(AmazonGamesClient.TAG, "Failed to send softkey press to APK: " + localRemoteException.toString());
        }
      }
    });
  }

  public static AmazonGames initialize(Application paramApplication, AmazonGamesCallback paramAmazonGamesCallback, EnumSet<AmazonGamesFeature> paramEnumSet)
  {
    try
    {
      INSTANCE = new AmazonGamesClient(paramApplication, paramAmazonGamesCallback, paramEnumSet);
      AmazonGames localAmazonGames = INSTANCE;
      return localAmazonGames;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  static void initialize(AmazonGames paramAmazonGames)
  {
    try
    {
      INSTANCE = paramAmazonGames;
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public final AchievementsClient getAchievementsClient()
  {
    return new AchievementsClientImpl(this.amazonGamesService, this.achievementsService);
  }

  public final Context getAppContext()
  {
    return this.context;
  }

  public final LeaderboardsClient getLeaderboardsClient()
  {
    return new LeaderboardsClientImpl(this.amazonGamesService, this.leaderboardsService);
  }

  public final ProfilesClient getProfilesClient()
  {
    return new ProfilesClientImpl(this.amazonGamesService, this.profilesService);
  }

  public final AmazonGamesStatus getStatus()
  {
    return this.amazonGamesService.getStatus();
  }

  public final WhisperSyncClient getWhisperSyncClient()
  {
    return new WhisperSyncServiceProxy(this.context, this.amazonGamesService, this.apiHandler);
  }

  public void initializeJni()
  {
    AGSJniHandler.initializeJni(this);
  }

  public final boolean isReady()
  {
    return this.amazonGamesService.isReady();
  }

  public void setPopUpLocation(PopUpLocation paramPopUpLocation)
  {
    PopUpPrefs.INSTANCE.setLocation(paramPopUpLocation);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.amazon.ags.api.AmazonGamesClient
 * JD-Core Version:    0.6.2
 */